from django.db import models

# Create your models here.

class Admin(models.Model):

    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=20)


class Press(models.Model):

    id = models.AutoField(primary_key=True)
    pressname = models.CharField(max_length=255)
    pressaddress = models.CharField(max_length=255)

    def __str__(self):
        return "出版社名称：%s,出版社地址：%s" % (self.pressname, self.pressaddress)

class Book(models.Model):
    id = models.AutoField(primary_key=True)
    bookname = models.CharField(max_length=255)
    bookprice = models.DecimalField(max_digits=5, decimal_places=2)
    bookauthor = models.CharField(max_length=255)
    bookimg = models.CharField(max_length=255)
    press = models.ForeignKey(to="Press", on_delete=models.SET_NULL,null=True,blank=True)

    def __str__(self):
        # 根据实际情况返回有意义的字段，比如书名
        return self.bookname  # 或者其他能标识这本书的字段
class BookType(models.Model):
    id = models.AutoField(primary_key=True)
    typename = models.CharField(max_length=255)
    books = models.ManyToManyField(to="Book")

    def __str__(self):
        return self.typename

# class Booktype_Book(models.Model):
#     id = models.AutoField(primary_key=True)
#     book = models.ForeignKey(to="Book", on_delete=models.SET_NULL,null=True,blank=True)
#     booktype = models.ForeignKey(to="BookType", on_delete=models.SET_NULL,null=True,blank=True)